package com.bdqn.ch06;

import com.bdqn.ch06.vo.Dept;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

@RunWith(SpringRunner.class)
@SpringBootTest
public class RedisTemplateTester {

    @Resource
    RedisTemplate redisTemplate;

    @Resource
    StringRedisTemplate stringRedisTemplate;

    @Resource
    ApplicationContext applicationContext;

    @Resource
    Dept caiwubuDept;

    @Autowired
    @Qualifier(value = "renshibuDept")
    Dept renshibuDept;

    @Test
    public void redisTester() {
        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
   /*         if (beanDefinitionName.equals("stringRedisTemplate") || beanDefinitionName.equals("redisTemplate")) {
                System.out.println("beanDefinitionName:" + beanDefinitionName);
            }*/
            if (beanDefinitionName.equals("caiwubuDept") || beanDefinitionName.equals("renshibuDept")) {
                System.out.println("dept:" + beanDefinitionName);
                System.out.println(caiwubuDept.getName());
                System.out.println(renshibuDept.getName());
            }
        }
    }

    @Test
    public void stringRedisTester() {
        stringRedisTemplate.opsForValue().set("love", "girl");
    }
}
